package cate.game.role.show.msg;

import cate.common.table.d.GD;
import cate.game.GameBody;
import cate.game.client.ClientContext;
import cate.game.client.msg.ClientMsg;
import cate.game.client.msg.MsgConfig;
import cate.game.client.msg.MsgInput;
import cate.game.client.msg.id.MsgIdBBlog;
import cate.game.role.Role;
import easy.java.dev.note.NoteField;
import easy.java.practice.errorcode.EcResult;

@ClientMsg(title = "修改性别 の 请求")
public class ModifySexReq implements MsgInput {

    @NoteField("性别")
    public byte sex;

    @Override
    public void execute(GameBody game, ClientContext cc) {
       EcResult r =  settle(cc.getRole());
       game.notice.message(cc.getRole(), r, true);
    }

    private EcResult settle(Role role) {
        EcResult r = new EcResult();
        if (sex != GD.Gender.MALE && sex != GD.Gender.FEMALE) {
            return r.fail("性别有误");
        }
        role.getBase().sex = sex;
        role.sendNow(new ModifySexResp(role));
        return r.success();
    }

    @Override
    public MsgConfig conf() {
        return MsgIdBBlog.MODIFY_SEX_REQ;
    }
}
